from clusterer.clusterer import Clusterer
import sklearn.cluster


# BIRCH
class Birch(Clusterer):
    # 类别数
    n_clusters = None
    
    def __init__(self):
        Clusterer.__init__(self)
        self.algorithm_name = "BIRCH"
        self.ipynb_template_name = "birch-template.ipynb"
        
    def implent(self): 
        Clusterer.implent(self)
        # 构造模型
        self.algorithm = sklearn.cluster.Birch(n_clusters=self.n_clusters)
        # 分类
        self.algorithm.fit(self.inputs)
        # 结果
        self.label_list = self.algorithm.labels_
        self.cluster_count = len(set(self.algorithm.labels_))
        # 保存xlsx
        self.saveToExcle()
        # 绘图
        self.drawChart()
    
    def prepareIpynbItems(self):
        Clusterer.prepareIpynbItems(self)
        self.ipynb_items["#n_clusters#"] = self.n_clusters
